# -*- coding: utf-8 -*-
from zinx.ziface.irequest import IRequest
from zinx.ziface.imessage import IMessage
from zinx.ziface.iconnection import IConnection


class Request(IRequest):
    def __init__(self, conn: IConnection, msg: IMessage):
        """
        :param conn: 已经和客户端建立好的 链接
        :param msg: 客户端请求的数据
        """
        self.Conn: IConnection = conn
        self.Msg: IMessage = msg

    def GetConnection(self) -> IConnection:
        """
        获取请求连接信息
        :return:
        """
        return self.Conn

    def GetData(self) -> bytes:
        """
        获取请求消息的数据
        :return:
        """
        return self.Msg.GetData()

    def GetMsgID(self) -> int:
        """
        获取请求消息的ID
        :return:
        """
        return self.Msg.GetMsgId()


def NewRequest(conn: IConnection, msg: IMessage) -> IRequest:
    req = Request(conn, msg)
    return req
